Import the library.


In [1]:
import polypy

Create variables $x$, $y$, $z$.


In [2]:
x = polypy.Variable('x')

In [3]:
[y, z] = [polypy.Variable(s) for s in ['y', 'z']]

Variable Ordering:

  • global variable order as a list $order = [x_1, \ldots, x_n]$;
  • $x \in order, y \notin order$: $x < y$;
  • $x \in order, y \in order$: ordered according to the list
  • $x \notin order, y \notin order$: order according to variable id

In [4]:
order = polypy.variable_order

In [5]:
order.push(z)

In [6]:
order.push(y)

In [7]:
order


Out[7]:
polypy.VariableOrder([z, y])

In [8]:
order.pop()

In [9]:
order.push(x)

In [10]:
order


Out[10]:
polypy.VariableOrder([z, x])

Creating Polynomials:

  • variables, constants
  • arithmetic operations
$$f = (x^2 - 2x + 1)(x^2 - 2), g = z(x^2 - y^2)$$

In [11]:
f = (x**2 - 2*x + 1)*(x**2 - 2)

In [12]:
g = z*(x**2 - y**2)

Variable order & Polynomials


In [13]:
order.set([x, y, z])

In [14]:
print g


(-1*y**2 + (1*x**2))*z

In [15]:
order.set([z, y])

In [16]:
print g


(1*z)*x**2 + ((-1*z)*y**2)

Basic operations


In [17]:
g.var()


Out[17]:
polypy.Variable('x')

In [18]:
g.degree()


Out[18]:
2

In [19]:
g.coefficients()


Out[19]:
[(-1*z)*y**2, 0, 1*z]

In [20]:
g.derivative()


Out[20]:
(2*z)*x

In [21]:
f.factor_square_free()


Out[21]:
[(1*x**2 - 2, 1), (1*x - 1, 2)]

In [22]:
g.factor_square_free()


Out[22]:
[(1*z, 1), (1*x**2 + (-1*y**2), 1)]

In [23]:
f


Out[23]:
1*x**4 - 2*x**3 - 1*x**2 + 4*x - 2

In [24]:
f.reductum()


Out[24]:
-2*x**3 - 1*x**2 + 4*x - 2

Root isolation:

  • assignment maps variables to values
  • we can isolate roots of univariate polynomials

In [25]:
m = polypy.Assignment()

In [26]:
r = f.roots_isolate(m)

In [27]:
r


Out[27]:
[<1*x**2 + (-2), (-3/2, -5/4)>, 1, <1*x**2 + (-2), (5/4, 3/2)>]

In [28]:
print r[0]


<1*x**2 + (-2), (-3/2, -5/4)>

In [29]:
print r[1]


1

In [30]:
print r[2]


<1*x**2 + (-2), (5/4, 3/2)>

Values can be integers, rationals, or algebraic numbers.


In [31]:
r[0].to_double()


Out[31]:
-1.414213562373095

In [32]:
r[0] > r[1]


Out[32]:
False

In [33]:
r[0].get_value_between(r[1])


Out[33]:
-1

In [34]:
m.set_value(x, 0)

In [35]:
f.sgn(m)


Out[35]:
-1

In [36]:
m.set_value(x, r[0])

In [37]:
f.sgn(m)


Out[37]:
0

In [ ]: